Skip to content

feat(browser): specialize browser prompt - #151

Draft
gregpr07 wants to merge 1 commit into
mainfrom
lean-browser-prompt
Draft

feat(browser): specialize browser prompt#151
gregpr07 wants to merge 1 commit into
mainfrom
lean-browser-prompt

Conversation

@gregpr07

@gregpr07 gregpr07 commented Aug 17, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace the 1,519-word generic GPT prompt with a 177-word browser-task prompt.
  • Reduce the browser-execute skill from 1,758 to 362 words while preserving current V4 auto-connect, reattachment, navigation-error, screenshot, and timeout guidance.
  • Emphasize bounded browser calls, structured checkpoints, record identity, required-field auditing, and explicit evidence-backed limitations.
  • Keep the provider text-verbosity defaults unchanged.

Evaluation evidence

The earlier 106-task experiment bundle improved from 81/106 to 88/106 while agent cost fell from $176.92 to $141.91 and timeouts fell from 6 to 3. Non-cached input per model call fell from about 8,110 to 2,231 tokens.

That run also included a BrowserCode version upgrade and eval-adapter hardening, so it is directional evidence rather than an isolated prompt A/B. This PR ports only the context-reduction changes onto current main. The GPT-5.5 medium-verbosity override is intentionally excluded because it was not isolated.

Verification

  • Pre-push filtered typecheck: 17/17 packages passed.
  • browser-execute skill tests: 2/2 passed.
  • Full bcode-browser suite: 35 passed, 8 skipped, with one unrelated existing workspace cache-busting test failure (temporary imported module not found).

Summary by cubic

Specializes the agent’s system prompt for browser tasks and condenses the browser_execute skill. This reduces token usage while keeping V4 auto-connect, reattach behavior, navigation-error handling, screenshot auto-attach, and timeout guidance. Directionally improved evals (81→88/106), lower cost ($176.92→$141.91), and fewer timeouts (6→3).

  • packages/opencode/src/session/prompt/gpt.txt: Replaces a ~1.5k-word generic prompt with a ~177-word browser-native prompt. Emphasizes bounded CDP calls, persistent session reuse, evidence-backed outputs, and required-field auditing. Removes broad editing/formatting guidance; confirm no workflows depend on that guidance.
  • packages/bcode-browser/skills/browser-execute/SKILL.md: Shrinks 1.7k→360 words. Preserves attach and reattach on -32001, Page.navigate.errorText handling, screenshot auto-attachment, cache-busted await import(...), and ERR_TUNNEL_CONNECTION_FAILED guidance. Removes step-by-step Chrome launch and Browser Use Cloud provisioning examples; verify the remaining connect/attach examples still cover common flows.

Rollout

  • No runtime code changes; provider verbosity defaults unchanged. No migrations required.
  • Verified: typecheck 17/17, skill tests 2/2, browser suite 35 pass (8 skipped), with one unrelated workspace cache-busting test failure. Monitor non-browser tasks for regressions due to removed general guidance.

Written for commit 95c9f1c. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/bcode-browser/skills/browser-execute/SKILL.md">

<violation number="1" location="packages/bcode-browser/skills/browser-execute/SKILL.md:15">
P3: The connect condition is ambiguous and diverges from the code's actual gate. `browser-execute.ts` `ensureCloudConnected` auto-connects only when `V4_RUN_ID` is set AND at least one of `BU_CDP_WS`/`BU_CDP_URL` is set. The phrasing "When both `V4_RUN_ID` and `BU_CDP_WS` or `BU_CDP_URL` are set" can be read as `BU_CDP_URL` alone being sufficient, which would make an agent skip `session.connect()` in a run that lacks `V4_RUN_ID`. Rephrase to require `V4_RUN_ID` and at least one CDP endpoint var.</violation>

<violation number="2" location="packages/bcode-browser/skills/browser-execute/SKILL.md:40">
P2: In the Drive example, `navigation.errorText` is checked only after `await loaded`. When navigation fails, CDP never emits `Page.loadEventFired`, so `await loaded` times out after 15s with a misleading "Timeout waiting for Page.loadEventFired" and the real `errorText` is hidden. Check `errorText` immediately after `navigate`, before awaiting the load waiter.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

const navigation = await session.Page.navigate({url: "https://example.com"})
await loaded
// Page.navigate resolves even on network errors — its result carries `errorText` when the load failed.
if (navigation.errorText) throw new Error(navigation.errorText)

@cubic-dev-ai cubic-dev-ai Bot Aug 17, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: In the Drive example, navigation.errorText is checked only after await loaded. When navigation fails, CDP never emits Page.loadEventFired, so await loaded times out after 15s with a misleading "Timeout waiting for Page.loadEventFired" and the real errorText is hidden. Check errorText immediately after navigate, before awaiting the load waiter.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/bcode-browser/skills/browser-execute/SKILL.md, line 40:

<comment>In the Drive example, `navigation.errorText` is checked only after `await loaded`. When navigation fails, CDP never emits `Page.loadEventFired`, so `await loaded` times out after 15s with a misleading "Timeout waiting for Page.loadEventFired" and the real `errorText` is hidden. Check `errorText` immediately after `navigate`, before awaiting the load waiter.</comment>

<file context>
@@ -1,209 +1,72 @@
+const navigation = await session.Page.navigate({url: "https://example.com"})
 await loaded
-// Page.navigate resolves even on network errors — its result carries `errorText` when the load failed.
+if (navigation.errorText) throw new Error(navigation.errorText)
 
-// Evaluate JS in the page.
</file context>
Fix with cubic

#### Way 1: connect to the user's running Chrome or Chromium-based browser (real profile, popup-gated).
Choose when the task involves the user's logged-in sites, current browser state, cookies, saved data, etc.
Browser Use Cloud API V4 automatically connects and attaches the existing page. When both `V4_RUN_ID` and
`BU_CDP_WS` or `BU_CDP_URL` are set, start driving immediately; do not call `session.connect()` or `session.use()`.

@cubic-dev-ai cubic-dev-ai Bot Aug 17, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The connect condition is ambiguous and diverges from the code's actual gate. browser-execute.ts ensureCloudConnected auto-connects only when V4_RUN_ID is set AND at least one of BU_CDP_WS/BU_CDP_URL is set. The phrasing "When both V4_RUN_ID and BU_CDP_WS or BU_CDP_URL are set" can be read as BU_CDP_URL alone being sufficient, which would make an agent skip session.connect() in a run that lacks V4_RUN_ID. Rephrase to require V4_RUN_ID and at least one CDP endpoint var.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/bcode-browser/skills/browser-execute/SKILL.md, line 15:

<comment>The connect condition is ambiguous and diverges from the code's actual gate. `browser-execute.ts` `ensureCloudConnected` auto-connects only when `V4_RUN_ID` is set AND at least one of `BU_CDP_WS`/`BU_CDP_URL` is set. The phrasing "When both `V4_RUN_ID` and `BU_CDP_WS` or `BU_CDP_URL` are set" can be read as `BU_CDP_URL` alone being sufficient, which would make an agent skip `session.connect()` in a run that lacks `V4_RUN_ID`. Rephrase to require `V4_RUN_ID` and at least one CDP endpoint var.</comment>

<file context>
@@ -1,209 +1,72 @@
-#### Way 1: connect to the user's running Chrome or Chromium-based browser (real profile, popup-gated). 
-Choose when the task involves the user's logged-in sites, current browser state, cookies, saved data, etc.
+Browser Use Cloud API V4 automatically connects and attaches the existing page. When both `V4_RUN_ID` and
+`BU_CDP_WS` or `BU_CDP_URL` are set, start driving immediately; do not call `session.connect()` or `session.use()`.
 
-```js
</file context>
Fix with cubic

@Alezander9
Alezander9 marked this pull request as draft August 18, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant